package com.ruoyi.controller.fanruan;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.jpjs.common.fanruan.WlFirst;
import com.ruoyi.service.fanruan.IWlFirstService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 文旅集团Controller
 *
 * @author ruoyi
 * @date 2020-11-04
 */
@Controller
@RequestMapping("/fanruan/wl")
public class WlFirstController extends BaseController
{
    private String prefix = "fanruan/wl";

    @Autowired
    private IWlFirstService wlFirstService;

    @RequiresPermissions("fanruan:wl:view")
    @GetMapping()
    public String wl()
    {
        return "fanruan/wl/wl";
    }

    /**
     * 查询文旅集团列表
     */
    @RequiresPermissions("fanruan:wl:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WlFirst wlFirst)
    {
        startPage();
        List<WlFirst> list = wlFirstService.selectWlFirstList(wlFirst);
        return getDataTable(list);
    }

    /**
     * 导出文旅集团列表
     */
    @RequiresPermissions("fanruan:wl:export")
    @Log(title = "文旅集团", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WlFirst wlFirst)
    {
        List<WlFirst> list = wlFirstService.selectWlFirstList(wlFirst);
        ExcelUtil<WlFirst> util = new ExcelUtil<WlFirst>(WlFirst.class);
        return util.exportExcel(list, "wl");
    }

    /**
     * 新增文旅集团
     */
    @GetMapping("/add")
    public String add()
    {
        return "fanruan/wl/add";
    }

    /**
     * 新增保存文旅集团
     */
    @RequiresPermissions("fanruan:wl:add")
    @Log(title = "文旅集团", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WlFirst wlFirst)
    {
        return toAjax(wlFirstService.insertWlFirst(wlFirst));
    }

    /**
     * 修改文旅集团
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WlFirst wlFirst = wlFirstService.selectWlFirstById(id);
        mmap.put("wlFirst", wlFirst);
        return "fanruan/wl/edit";
    }

    /**
     * 修改保存文旅集团
     */
    @RequiresPermissions("fanruan:wl:edit")
    @Log(title = "文旅集团", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WlFirst wlFirst)
    {
        return toAjax(wlFirstService.updateWlFirst(wlFirst));
    }

    /**
     * 删除文旅集团
     */
    @RequiresPermissions("fanruan:wl:remove")
    @Log(title = "文旅集团", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wlFirstService.deleteWlFirstByIds(ids));
    }
}
